{include file="layout/layout"}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3>代理管理 - 添加代理区域</h3>
                <h5>网站系统添加代理</h5>
            </div>
        </div>
    </div>
    <form class="form-horizontal" method="post" id="add_form" action="{:url('admin/agents/permitAllocation')}" onsubmit="return false" >
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="nickname"><em>*</em>代理账户</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="age_username" id="nickname" readonly="" value="{$res['age_username']}" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">不可修改</p>
                </dd>
            </dl>
            <input type="hidden" name="id" value="{$id}">

            <dl class="row">
                <dt class="tit">
                    <label for="consignee"><em>*</em>区域</label>
                </dt>
                <dd class="opt">
                    <select onchange="get_city(this)" id="province" name="province" title="请选择所在省份">
                        <option value="">选择省份</option>
                        {volist name="province" id="pv"}
                        <option value="{$pv['id']}">{$pv['name']}</option>
                        {/volist}
                    </select>
                    <select onchange="get_area(this)" id="city" name="city" title="请选择所在城市">
                        <option value="">选择城市</option>
                    </select>
                    <select id="district" name="region" title="请选择所在区县">
                        <option value="">选择区域</option>
                    </select>
                    <!--<input type="text" name="address" id="address" class="input-txt" placeholder="详细地址">-->
                    <span class="err"></span>
                    <p class="notic">请依次选择对应区域</p>
                </dd>
            </dl>


            <div class="bot"><input type="submit"  value="确认添加" class="ncap-btn-big ncap-btn-green" id="checkUserUpdate"></div>
        </div>
    </form>
    <!--<form class="form-horizontal" method="post" id="add_form" action="{:url('admin/agents/permitAllocation')}">-->
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="nickname"><em>*</em>已代理区域</label>
                </dt>
            </dl>
            <input type="hidden" name="id" value="{$id}">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0" style="margin-left: 150px;   ">
                <table>
                    <tbody>
                    {volist name="area" id="agents"}
                    <tr>
                        <td class="sign">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </td>
                        <td align="left" class="">
                            <div style="text-align: left; width: 50px;">{$agents['agea_agent_manage']}</div>
                        </td>
                        <td align="left" class="">
                            <div style="text-align: left; width: 350px;">{$agents['merger_name']}</div>
                        </td>

                        <td align="center" class="handle">
                            <div style="text-align: center; width: 170px; max-width:170px;">
                                <a class="btn red" href="javascript:void(0)" data-url="/index.php/admin/agents/areaDelete" data-id2="{$agents['agea_area']}" data-id="{$agents['agea_agent_manage']}"  onclick="delfun(this)"><i class="fa fa-trash-o"></i>删除</a>
                            </div>
                        </td>
                        <td align="" class="" style="width: 100%;">
                            <div>&nbsp;</div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

        </div>


</div>

<script>
    /**
     * 获取城市
     * @param t  省份select对象
     */
    function get_city(t){

        var parent_id = $(t).val();
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','none');
        $('#twon').empty().css('display','none');
        var url = "{:url('agents/getRegion')}";

        $.ajax({
            type : "GET",
            url  : url,
            data:{level:2,parent_id: parent_id},
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option value="0">选择城市</option>'+ v;
                $('#city').empty().html(v);
            }
        });
    }
    /**
     * 获取地区
     * @param t  城市select对象
     */
    function get_area(t){
        var parent_id = $(t).val();
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','inline');
        $('#twon').empty().css('display','none');
        var url = "{:url('agents/getRegion')}";
        $.ajax({
            type : "GET",
            url  : url,
            data:{level:3,parent_id: parent_id,type:1},
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option>选择区域</option>'+ v;
                $('#district').empty().html(v);
            }
        });
    }

</script>
<script>
    $('#district').change(function () {

        $('#add_form').attr('onsubmit','true');


    });

</script>
<script>
    function delfun(obj){
        layer.confirm('确认删除？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    type : 'get',
                    url : $(obj).attr('data-url'),
                    data : {agem_id:$(obj).attr('data-id'),agea_area:$(obj).attr('data-id2')},
                    dataType : 'json',
                    success : function(data){
                        layer.closeAll();
                        if(data.status==1){
                            layer.msg('操作成功', {icon: 1});
                            $(obj).parent().parent().parent().remove();
                        }else{
                            layer.msg(data, {icon: 2,time: 2000});
                        }
                        layer.closeAll();
                    }
                })
            }, function(index){
                layer.close(index);
                return false;// 取消
            }
        );
    }
</script>